<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: green;
            position: absolute;
            left: 0;
        }
    </style>
</head>
<body>
    <div class="box">

    </div>
    <script>
        const box = document.querySelector('.box');
        let dis = 0;
        // setInterval(() => {
        //     box.style.left = ++dis + 'px';
        //     if (dis >= 500) {
        //         clearInterval(interval);
        //     }
        // },6);
        function animation() {
            requestAnimationFrame(function() {
                // console.log('....');
                box.style.left = ++dis + 'px';
                animation(); //递归
                if(dis >= 500) {
                    
                }
            })
        }
        animation();
    </script>
</body>
</html>